package www.study.com;

public class code45 {
    public static void main(String[] args) {

    }

    class Solution {
        public int jump(int[] nums) {
            int mostReg = 0; //当前最优跳跃所能够到达的最优右位置
            int nextMost = 0; //再次跳跃所能够达到的最右位置
            int cnt = 0; //跳跃次数
            for(int i = 0 ; i < nums.length - 1 ; i++){
                nextMost = Math.max(nextMost,i + nums[i]);
                if(mostReg == i){ //到达边界，需要再次跳跃
                    mostReg = nextMost;
                    cnt++;
                }
            }
            return cnt;
        }
    }
}
